import {
  timeFormat,getEllipsisString
} from '../../utils/utils'
const app = getApp()
import Toast from '@vant/weapp/toast/toast'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dataList: [],
    activeNames: ['1'],
    pageData: {
      pageNo: 1,
      pageSize: 10
    },
    ispage:false
  },
  onChange(event) {
    this.setData({
      activeName: event.detail,
    });
  },
  getList(val) {
    let that = this
    Toast.loading({
      message: '加载中...',
      forbidClick: true,
    });
    let params = {}
    params.page = that.data.pageData.pageNo
    app.globalData.header.Authorization = wx.getStorageSync('token')
    wx.request({
      url: app.serverUrl + '/api/order',
      header: app.globalData.header,
      method: 'POST',
      data: params,
      success: res => {
        if (res.data.code == 200) {
          if(res.data.data.length<10){
            that.setData({
              ispage:true
            })
          }
          // res.data.data.map(item => {
          //   item.money = parseInt(item.money)
          // })
          Toast.clear()
          wx.hideNavigationBarLoading();
          if(val){
            that.setData({
              dataList:that.data.dataList.concat(res.data.data) 
            })
          }else{
            that.setData({
              dataList:res.data.data
            })
          }
          
        }
      }
    })
  },
  detailsHeld(e) {
    wx.navigateTo({
      url: '/pages/details/awarddetails/awarddetails?Val=' + JSON.stringify(e.currentTarget.dataset.val),
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    if(this.data.dataList.length==0){
      this.getList()
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    let that = this
    wx.showNavigationBarLoading()
    wx.stopPullDownRefresh();
    that.setData({
      'pageData.pageNo': 1,
      ispage:false
    })
    that.getList()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    
    let that = this
    if(that.data.ispage) return
    let page = that.data.pageData.pageNo
    page += 1
    that.setData({
      'pageData.pageNo': page
    })

    that.getList(1)
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})